package logic.UIProxyBag.uieditescene
{
	import common.core.GEevnt;
	import common.core.UIService;
	import common.manager.GUI;
	import common.manager.ObserverEvt;
	
	import component.show.containers.*;
	import component.untils.ComponentItem;
	
	import logic.cmd.OpenUIXMLCMD;
	import logic.def.Def;
	import logic.ui.componentInfoMed.ImageInfoMed;
	import logic.ui.uieditscene.ScanComponentMed;
	import logic.ui.uieditscene.ScanUITreeMed;
	import logic.ui.uieditscene.TopBar;
	import logic.ui.uieditscene.UIContainMed;

	public class UIContainProxy extends UIService
	{
		public function UIContainProxy()
		{
		}
		
		public override function destory():void
		{
			
		}
		
		public override function start(value:* = null):void
		{	
			var ui : UIContainMed = new UIContainMed;
			
			GUI.add(UIContainMed.NAME,ui,false);
			GUI.setAlgin(UIContainMed.NAME,GUI.ALIGN_LEFT,GUI.ALIGN_TOP);
			GUI.setOffest(UIContainMed.NAME,150,22);
			
			GUI.open(UIContainMed.NAME);
			
			ObserverEvt.addRec(ScanComponentMed.SCANCOMPONENT_CLICKCOMPONENTLSTCELL,this,OnRecClickComponentLstCell);
			ObserverEvt.addRec(ImageInfoMed.SELECTIMAGE,this,OnSelectImageSkin);
			ObserverEvt.addRec(OpenUIXMLCMD.OPENCOMPLETE,this,onRecOpenUIXMLComplete);
			ObserverEvt.addRec(Def.COMPONENTPROPERTYCHANGED,this,onRecComponentPropertyChangedMsg);
			
			ObserverEvt.addRec(TopBar.OPENUIXML,this,onClickOpenUIXMLBtn);
			ObserverEvt.addRec(TopBar.SAVEUIXML,this,onClickSaveBtn);
			ObserverEvt.addRec(TopBar.DELUICOM,this,onClickDelUICom);
			
			ObserverEvt.addRec(ScanUITreeMed.CLICKUITREENODE,this,onRecClickUITreeNode);
			ObserverEvt.addRec(UIContainMed.COMPONENTCONTROLACTIVE,this,compoentControlLockedStatu);
		}
		
		public override function stop():void
		{
			GUI.remove(UIContainMed.NAME);
			
			ObserverEvt.removeRec(ScanComponentMed.SCANCOMPONENT_CLICKCOMPONENTLSTCELL,this,OnRecClickComponentLstCell);
			ObserverEvt.removeRec(ImageInfoMed.SELECTIMAGE,this,OnSelectImageSkin);
			ObserverEvt.removeRec(OpenUIXMLCMD.OPENCOMPLETE,this,onRecOpenUIXMLComplete);
			ObserverEvt.removeRec(Def.COMPONENTPROPERTYCHANGED,this,onRecComponentPropertyChangedMsg);
			
			ObserverEvt.removeRec(TopBar.OPENUIXML,this,onClickOpenUIXMLBtn);
			ObserverEvt.removeRec(TopBar.SAVEUIXML,this,onClickSaveBtn);
			ObserverEvt.removeRec(TopBar.DELUICOM,this,onClickDelUICom);
			
			ObserverEvt.removeRec(ScanUITreeMed.CLICKUITREENODE,this,onRecClickUITreeNode);
			ObserverEvt.removeRec(UIContainMed.COMPONENTCONTROLACTIVE,this,compoentControlLockedStatu);
		}
		
		/**
		 * 接受到选中组件的事件
		 * @param evt 
		 */		
		private function OnRecClickComponentLstCell(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).clearSelectTarget(); 
		}
		
		/**
		 * 选中皮肤
		 * @param evt 
		 */		
		private function OnSelectImageSkin(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).setSelectSkin(evt.data);
		}
		
		/**
		 * 打开界面XML完成事件
		 * @param evt 
		 */	
		private function onRecOpenUIXMLComplete(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).openUIXML(evt.data);
		}
		
		/**
		 * 收到属性面板目标属性改变的消息 
		 */		
		private function onRecComponentPropertyChangedMsg(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).updateComProperty();
		}
		
		/**
		 * 打开界面xml
		 * @param evt 
		 */	
		private function onClickOpenUIXMLBtn(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).openUIXMLByBrower( );
		}
		
		/**
		 * 保存界面xml
		 * @param event 
		 */		
		private function onClickSaveBtn(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).saveBtnByBrower();
		}
		
		/**
		 * 删除组件
		 * @param evt 
		 */	
		private function onClickDelUICom(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).removeComponent();
		}
		
		private function onRecClickUITreeNode( evt : GEevnt ): void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).setOperTarget(evt.data);
		}
		
		/**
		 * 获取UI面板组
		 * @return  
		 */		
		public function get uiRootFrameGroup() : Vector.<ComponentItem>
		{
			return (GUI.find(UIContainMed.NAME) as UIContainMed).uiRootFrameGroup;
		}
		
		/**
		 * 设置被控制的组建是否锁定
		 * @param value 
		 */		
		private function  compoentControlLockedStatu(evt : GEevnt) : void
		{
			(GUI.find(UIContainMed.NAME) as UIContainMed).compoentControlLockedStatu = evt.data;
		}
	}
}